package com.lkd.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lkd.dto.ReportDto;
import com.lkd.entity.Task;
import com.lkd.mapper.TaskMapper;
import com.lkd.service.ITaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lkd.vo.PageBean;
import com.lkd.vo.TaskVVo;
import com.lkd.vo.TaskVo;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

/**
 * <p>
 * 工单表 服务实现类
 * </p>
 *
 * @author zzy
 * @since 2025-11-01
 */
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {

    /**
     * 工单统计
     *
     * @param reportDto
     * @return
     */
    @Override
    public List<TaskVVo> taskReportInfo(ReportDto reportDto) {

        List<TaskVo> list = baseMapper.searchTask(reportDto.getStart(), reportDto.getEnd());

        List<TaskVVo> collect = list.stream().map(item -> {
            TaskVVo taskVVo = new TaskVVo();
            BeanUtil.copyProperties(item, taskVVo);
            //repair
            if (item.getRepair()==1){
                taskVVo.setRepair(true);
            }else {
                taskVVo.setRepair(false);
            }
            //人数
            taskVVo.setWorkerCount(0);
            //当前时间
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH);
            String currentDateStr = ZonedDateTime.now(ZoneId.systemDefault()).format(formatter);
            taskVVo.setDate(currentDateStr); // 现在传入的是String类型
            return taskVVo;
        }).collect(Collectors.toList());

        return collect;

    }

}
